package br.affero.core.person.model;

import javax.faces.component.UIComponent;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;

import org.jboss.seam.faces.conversion.Converter;

import br.affero.core.person.dao.PersonDao;

@FacesConverter("personConverter")
public class PersonConverter extends Converter<Person> {
	@Inject
	PersonDao personDao;

	@Override	
	public Person toObject(UIComponent uic, String string) {
        Integer id = Integer.parseInt(string);
        return personDao.findById(id);
    }

	@Override
	public String toString(UIComponent uic, Person p) {
        return p.getPersonId().toString();
    }
}
